package lime.group.view;

import lime.model.Group;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

public class GroupFilter extends ViewerFilter {

	private String contains;
	private String groupClass;
	
	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {

		Group group = (Group) element;
		
		if (StringUtils.isNotBlank(groupClass)) {
			if (!group.getGroupClass().equals(groupClass)) {
				return false;
			}
		}
		
		if (StringUtils.isNotBlank(contains)) {
			String regex = ".*" + contains + ".*";
			if (!group.getObjectName().matches(regex)) {
				return false;
			}
		}
		
		return true;
	}
	
	public String getContains() {
		return contains;
	}
	
	public void setContains(String contains) {
		this.contains = contains;
	}
	
	public String getGroupClass() {
		return groupClass;
	}
	
	public void setGroupClass(String groupClass) {
		this.groupClass = groupClass;
	}
	
	

}
